package cloud.server1.service.task;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Date;

import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.stereotype.Service;

import kilim.Mailbox;
import kilim.Pausable;
import kilim.Task;

@Service
public class TaskD extends Task {
	public static Mailbox<String> MB = new Mailbox<String>();
	public void execute() throws Pausable {
		for (int i = 0; i < 100; i++) {
			Thread cu = Thread.currentThread();
			try {
				HttpGet request = new HttpGet("http://localhost:8771/kilim/sendAndReceive");
				// 获取当前客户端对象
				HttpClient httpClient = HttpClients.createDefault();
				// 通过请求对象获取响应对象
				HttpResponse response = httpClient.execute(request);
				// 判断网络连接状态码是否正常(0--200都数正常)
				if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
					String result = EntityUtils.toString(response.getEntity(), "utf-8");
					String rString = result;
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			System.out.println("TaskD:运行位置  " + i + " 当前线程 " + cu.getId()+" 时间 "+new Date().toLocaleString());
		}
	}
}
